#!/usr/bin/perl 

use strict;
use DBI;
use CGI;
use TTraker;

my $dbh;
initialize_dbi;

print_header;

my $form_ref = &parse_input;
my %FORM_DATA = %$form_ref;

my $supNum = $FORM_DATA{'supNum'};
my $supName = $FORM_DATA{'supName'};
my $supJob = $FORM_DATA{'supJob'};
my $supLoc = $FORM_DATA{'supLoc'};
my $empNum = $FORM_DATA{'empNum'};
my $empName = $FORM_DATA{'empName'};
my $payDate = $FORM_DATA{'payDate'};
my $jobNum = $FORM_DATA{'jobID'};

# my $jobInfo_ref = get_job_info(); 

my $str = create_tmp_task_table ($supNum, $supName, $supLoc, $empNum, $empName, $payDate, $jobNum);
draw_adjust_tasks_for_job ($supNum, $supName, $supJob, $supLoc, $empNum, $empName, $payDate, $jobNum, $str);

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################

sub draw_adjust_tasks_for_job
{
	my $supNum = $_[0];
	my $supName = $_[1];
	my $supJob = $_[2];
	my $supLoc = $_[3];
	my $empNum = $_[4];
	my $empName = $_[5];
	my $payDate = $_[6];
	my $jobNum = $_[7];
	my $str =  $_[8];
	my @taskData = ();
	my $taskDataRef = get_task_data ($supNum, $empNum, $jobNum, $payDate );
	@taskData = @$taskDataRef;
  print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_04_sup_adjust_task_data</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  <div id='box5_2'>
  <h3>Task Data: $empName : $payDate : $str </h3>
  <form onkeypress='return event.keyCode != 13;' autocomplete='off'  name='activity' action='${cgi_ref}trak_05_sup_task_adjust.pl' method='post'>
  <input type="hidden" name="supNum" value='$supNum'/>
  <input type="hidden" name="supName" value='$supName'/>
  <input type="hidden" name="supJob" value='$supJob'/>
  <input type="hidden" name="supLoc" value='$supLoc'/>
  <input type="hidden" name="empNum" value='$empNum'/>
  <input type="hidden" name="empName" value='$empName'/>
  <input type="hidden" name="payDate" value='$payDate'/>
  <input type="hidden" name="jobNum" value='$jobNum'/>
  <table id="small" cellspacing="0" cellpadding="1" border="1" width="500px">
	<tr>
		<th align=left width="50%">Description</th>
		<th align=center width="20%">Units</th>
		<th align=center width="15%">Total</th>
		<th align=center width="15%">Adjusted</th>
    </tr>
ENDHEADER
# <tbody class="scrollContent">	
 for my $i (0..$#taskData ) {
		my $chrgCode = $taskData[$i][0];		
		my $desc = $taskData[$i][1];	
		my $units = $taskData[$i][2];
		my $total = $taskData[$i][3];
		if ( ! $total) {
			$total = 0;
		}
		print <<ENDHEADER;
		<tr>
			<td align=left>$desc</td>
			<td  align=center>$units</td>
			<td align=center>$total</td>
			<td align=center><input type="text" size="12" name="TASK_$chrgCode" /></td>
		</tr>
ENDHEADER
 }
 print <<ENDHEADER;
 </table>
 <br/>
 <input type='submit' value='Adjust Task Data'>
 <br/>
 <br/>	
 <a href="${cgi_ref}trak_00_sup_activity.pl?num=$supNum&name=$supName&job=$supJob&loc=$supLoc">Return to Activities</a>
 <br/><br/>
 </form>
 </div>	
 </body>
 </html>
ENDHEADER
}



